//
//  QYGPersonalView.m
//  wawaji_ios
//
//  Created by yiguo qi on 2017/11/30.
//  Copyright © 2017年 yiguo qi. All rights reserved.
//

#import "QYGPersonalView.h"

@interface  QYGMineHeaderView()
@property (nonatomic, strong) UIButton *headerBtn;
@property(nonatomic, strong) UILabel *nameLabel;
@property(nonatomic, strong) UILabel *detailLabel;
@property(nonatomic, strong) UIView *whiteView;

@end



@implementation QYGMineHeaderView

- (void)setNameStr:(NSString *)nameStr detailStr:(NSString *)detailStr headerStr:(NSString *)headerStr{
    _nameStr = nameStr;
    _detailStr = detailStr;
    _headerStr = headerStr;
    self.nameLabel.text = nameStr;
    self.detailLabel.text = detailStr;
    [self.headerBtn  setBackgroundImageWithURL:[NSURL URLWithString:headerStr] forState:UIControlStateNormal placeholder:nil];
    
    [self.nameLabel sizeToFit];
    [self.detailLabel sizeToFit];
}
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        [self setupUI];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.headerBtn.centerX = self.centerX;
    self.headerBtn.y = ScaleH(50);
    
    self.nameLabel.centerX = self.headerBtn.centerX;
    self.nameLabel.y = CGRectGetMaxY(self.headerBtn.frame) + ScaleH(15);
    
    self.detailLabel.centerX = self.nameLabel.centerX;
    self.detailLabel.y = CGRectGetMaxY(self.nameLabel.frame) + ScaleH(10);
    
    self.whiteView.x = 0;
    self.whiteView.width = self.width;
    self.whiteView.height = ScaleW(40);
    self.whiteView.y = self.height - ScaleW(20);

    
    
}
- (void)setupUI{
    
    self.image = [UIImage imageNamed:@"mine_bg.png"];
    
    [self addSubview:self.headerBtn];
    [self addSubview:self.nameLabel];
    [self addSubview:self.detailLabel];
    [self addSubview:self.whiteView];
}

- (UIButton *)headerBtn{
    if(!_headerBtn){
        _headerBtn = [UIButton buttonWithBackgroundImageName:nil];
        _headerBtn.size = CGSizeMake(ScaleW(70), ScaleW(70));
        
        _headerBtn.layer.borderWidth = 2;
        _headerBtn.layer.borderColor = [UIColor whiteColor].CGColor;
        _headerBtn.layer.cornerRadius = ScaleW(35);
        _headerBtn.layer.masksToBounds = YES;
    }
    return _headerBtn;
}

- (UILabel *)detailLabel{
    if(!_detailLabel){
        _detailLabel = [UILabel labelWithText:@"ID:1314231" setFont:ScaleFont(13) setTextColor:[UIColor whiteColor]];
        [_detailLabel sizeToFit];
        _detailLabel.numberOfLines = 1;
    }
    return _detailLabel;
}
- (UILabel *)nameLabel{
    
    if(!_nameLabel){
        _nameLabel = [UILabel labelWithText:@"用户名" setFont:ScaleFont(16) setTextColor:[UIColor whiteColor]];
        [_nameLabel sizeToFit];
        _nameLabel.numberOfLines = 1;
    }
    return _nameLabel;
}

- (UIView *)whiteView{
    if(!_whiteView){
        _whiteView = [[UIView alloc] init];
        [_whiteView viewWithcornerRadius:ScaleW(20) borderWidth:0 borderColor:nil backgroundColor:[UIColor whiteColor]];
    }
    return _whiteView;
}
@end




@interface QYGPersonalView()

@property(nonatomic, strong, readwrite) UIButton *headBtn;
@property(nonatomic, strong) UILabel *nameLabel;
@property(nonatomic, strong) UIImageView *arrowImageView;
@property(nonatomic, strong) UILabel *detailLabel;

@end

@implementation QYGPersonalView


- (void)setNameStr:(NSString *)nameStr detailStr:(NSString *)detailStr headerStr:(NSString *)headerStr{
    _nameStr = nameStr;
    _detailStr = detailStr;
    self.nameLabel.text = nameStr;
    self.detailLabel.text = detailStr;
    [self.headBtn setBackgroundImageWithURL:[NSURL URLWithString:headerStr] forState:UIControlStateNormal placeholder:nil];
    
    [self.nameLabel sizeToFit];
    [self.detailLabel sizeToFit];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setBackgroundColor:[UIColor clearColor]];
        [self initSubview];
    }
    return self;
}
- (void)initSubview{
    
    [self addSubview:self.headBtn];
    [self addSubview:self.nameLabel];
    [self addSubview:self.detailLabel];
//    [self addSubview:self.arrowImageView];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.headBtn.centerY = self.height * 0.5;
    self.headBtn.x = ScaleH(12);
    self.headBtn.y = (self.height - self.headBtn.height) * 0.5;
    
    self.nameLabel.x = CGRectGetMaxX(self.headBtn.frame) + ScaleW(15);
    self.nameLabel.y = self.headBtn.y + ScaleH(3);
    
    self.detailLabel.x = self.nameLabel.x;
    self.detailLabel.y = CGRectGetMaxY(self.nameLabel.frame) + ScaleH(4);
    
    
//    self.arrowImageView.x = self.width - self.arrowImageView.width - ScaleW(15);
//    self.arrowImageView.centerY = self.headBtn.centerY;
    
    
}


- (UIImageView *)arrowImageView{
    if(!_arrowImageView){
        _arrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_white_arrows"]];
        
    }
    return _arrowImageView;
}
- (UILabel *)detailLabel{
    if(!_detailLabel){
        _detailLabel = [UILabel labelWithText:@"ID:1314231" setFont:ScaleFont(12) setTextColor:[UIColor whiteColor]];
        [_detailLabel sizeToFit];
        _detailLabel.numberOfLines = 1;
    }
    return _detailLabel;
}
- (UILabel *)nameLabel{
    
    if(!_nameLabel){
        _nameLabel = [UILabel labelWithText:@"用户名" setFont:ScaleFont(16) setTextColor:[UIColor whiteColor]];
        [_nameLabel sizeToFit];
        _nameLabel.numberOfLines = 1;
    }
    return _nameLabel;
}
- (UIButton *)headBtn{
    if(!_headBtn){
        _headBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        _headBtn.layer.borderWidth = 1;
        _headBtn.layer.borderColor = [UIColor whiteColor].CGColor;
        _headBtn.layer.cornerRadius = ScaleH(25);
        _headBtn.layer.masksToBounds = YES;
        _headBtn.size = CGSizeMake(ScaleH(50), ScaleH(50));
    }
    return _headBtn;
}
@end
